package com.fir.my.batis.plus.until;

public class String2AcsII16 {
    public static String go(String str){
        StringBuffer buffer = new StringBuffer();
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int asciiValue = chars[i];
//            System.out.println(chars[i] + " 的 ASCII 值为：" + asciiValue);
            String s = Integer.toHexString((int) chars[i]);
//            System.out.println(chars[i] + " 16进制 值为：" + s);
            int cut = 4 - s.length();
            if(s.length() < 4){
                for(int j = 0;j < cut ;j++){
                    s = "0" + s;
                }
            }
            buffer.append(s);
//            System.out.println(chars[i] + " 四位的 16进制 值为：" + s);
        }
        return buffer.toString();
    }
    public static int string2Char2asciiValue(String str){
        //  String str = "C";
//        if(str.length() > 1){
//            char c = str.charAt(0);
//            char c1 = str.charAt(1);
//        }
        char c = str.charAt(0);
//        System.out.println(c);
        int asciiValue = c;  //char 转 int
        return asciiValue;
    }
    public static String string2Char2asciiValueint10to16(String str){
        return int10to16(string2Char2asciiValue(str));
    }
    public static String string2Char2asciiValueint10to16_2(String str){
        return int10to16_2(string2Char2asciiValue(str));
    }
    public static String int10to16(int asciiValue10){
        String s16 = Integer.toHexString(asciiValue10);
        int cut = 4 - s16.length();
        if(s16.length() < 4){
            for(int j = 0;j < cut ;j++){
                s16 = "0" + s16;
            }
        }
//        System.out.println( " 四位的 16进制 值为：" + s16);
        return s16;
    }

    public static String int10to16_2(int asciiValue10){
        String s16 = Integer.toHexString(asciiValue10);
        int cut = 2 - s16.length();
        if(s16.length() < 2){
            for(int j = 0;j < cut ;j++){
                s16 = "0" + s16;
            }
        }
//        System.out.println( " 二位的 16进制 值为：" + s16);
        return s16;
    }


    public static void main(String[] args) {
//        System.out.println("C".charAt(0));
//        System.out.println(Integer.valueOf("C".charAt(0)));

        String C = int10to16(string2Char2asciiValue("C"));
        String value = int10to16(3075);
        String down = int10to16(2800);
        String up = int10to16(3100);
//        System.out.println(C + value+ down + up);
//        ChuanKou.sendStr("COM5",C + value + down + up);
    }

}
